<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        input {
            display: block;
            text-align: center;
            padding: 0px 20px;
            margin: 15px auto;

        }
    </style>
</head>

<body>
    <input type="button" value="0">
</body>

<script>
    window.onload = function () {
        var MyInput = document.getElementsByTagName('input')[0]
        console.log(MyInput);

        function sum() {
            var sum = parseInt(MyInput.value)
            var i = 1
            return (sum += 1)
        }

        MyInput.onclick = function () {
            alert(sum())
            this.value = sum()
        }
    }


</script>

</html>